package com.tencent.qcloud.tim.uikit.component.goods

import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.library.common.base.BindRecycAdapter
import com.tencent.qcloud.tim.uikit.R
import com.tencent.qcloud.tim.uikit.databinding.ItemGoodsSendBinding

class SendGoodsListAdapter : BindRecycAdapter<ItemGoodsSendBinding, GoodsDto>() {
    override fun onBindViewHolder(
        mBinding: ItemGoodsSendBinding,
        itemData: GoodsDto,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        mBinding.tvTitle.text = itemData.name
        mBinding.tvPrice.text = String.format(
            mContext.getString(R.string.price_with_value),
            itemData.salePrice
        )
        Glide.with(mContext).asBitmap().load(itemData.thumbnail).centerCrop()
            .placeholder(ContextCompat.getDrawable(mContext, R.drawable.default_image))
            .into(mBinding.ivImage)
        mBinding.btnSend.setOnClickListener {
            onClickSendGoodsListener.invoke(itemData)
        }
    }

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_goods_send
    }

    lateinit var onClickSendGoodsListener: (itemData: GoodsDto) -> Unit
}